<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>${message("添加任务单")}</title>
<link href="/resources/css/common.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/resources/js/reference/jquery.js"></script>
<script type="text/javascript" src="/resources/js/reference/jquery.validate.js"></script>
<script type="text/javascript" src="/resources/js/base/dialog.js"></script>
<script type="text/javascript" src="/resources/js/base/request.js"></script>
<script type="text/javascript" src="/resources/js/base/global.js"></script>
<script type="text/javascript" src="/resources/plugin/datePicker/WdatePicker.js"></script>
<link href="/resources/css/mmGrid.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/resources/js/reference/mmGrid.js"></script>
<script src="/resources/js/base/file.js"></script>
<script type="text/javascript">
function editQty(t,e){
	extractNumber(t,0,false,e);
}
$().ready(function() {
	var $inputForm = $("#inputForm");
	var $addElock = $("#addElock");
	var $deleteElock = $("a.deleteElock");

	//打开选择锁界面
    $addElock.click(function(){
        $addElock.bindQueryBtn({
            type:'elock',
            bindClick:false,
            title:'${message("查询")}',
    		url:'/car/select_elock_car_list.jhtml?multi=2',
            callback:function(rows){
                if(rows.length>0){
                    for (var i = 0; i < rows.length;i++) {
                    	var $car_number = $("input.plateNum[value='"+rows[i].car_number+"']");
                    	var $berth = $("input.berth[value='"+rows[i].berth+"']");
    					if($car_number.length>0&&$berth.length>0){
    						$.message_alert('车牌号为【'+rows[i].car_number+'】且舱位为【'+rows[i].berth+'】的明细已添加');
    						return false;
    					}
                    }
                    for (var i = 0; i < rows.length;i++) {
						var row = rows[i];
						row.plate_num=row.car_number;
						
						$tmGrid.addRow(row,null,1);
					}
                }
            }
        }); 
    })
	 
	var elockInItemIndex = 0;
 	var cols = [
		{ title:'${message("鹤位")}', name:'' ,align:'center', width:110, renderer: function(val,item,rowIndex, obj){
			
			var html='<div class="nums-input ov">'+
        	'<input type="button" class="b decrease" value="-"  onMouseDown ="decrease(this,event)"  onMouseUp="editQty(this.nextSibling,event)">'+
        	'<input type="text"  class="t requireds"  name="terminalTaskItems['+elockInItemIndex+'].position" value="" minData="1" maxData="4" oninput="editQty(this,event)" onpropertychange="editQty(this,event)" >'+
        	'<input type="button" value="+" class="b increase"  onMouseDown ="increase(this,event)" onMouseUp="editQty(this.previousSibling,event)">'+
    	'</div>';
			return html;
		}
		},
    	{ title:'${message("车牌号")}', name:'plate_num' ,align:'center', renderer: function(val,item,rowIndex, obj){
			var	html = val+'<input type="hidden" name="terminalTaskItems['+elockInItemIndex+'].plateNum" class="text plateNum" value="'+val+'" btn-fun="clear"/>';
			return html;
		} },
		{ title:'${message("舱位")}', name:'berth' ,align:'center', renderer: function(val,item,rowIndex, obj){
			var	html = val+'<input type="hidden" name="terminalTaskItems['+elockInItemIndex+'].berth" class="text berth" value="'+val+'" btn-fun="clear"/>';
			return html;
		} },
		{ title:'${message("卸油机构")}', name:'' ,align:'center', width:110, renderer: function(val,item,rowIndex, obj){
			var html='<span style="position:relative">'+
			'<input name="terminalTaskItems['+elockInItemIndex+'].toSaleOrg.id" class="text toSaleOrgId requireds" type="hidden" value="">'+
			'<input name="toSaleOrgName" class="text toSaleOrgName " maxlength="200" type="text" value="'+val+'" onkeyup="clearSelect(this)">'+
			'<input type="button" class="iconSearch " style="position: absolute;top: 0;right: 5px;" onclick="addtoSaleOrg(this,1)" value="" >'+
			'</span>';	
			return html;
		}
		},
    	{ title:'${message("出发时间")}', name:'' ,align:'center', width:130, renderer: function(val,item,rowIndex, obj){
    		return '<input  id="terminalTaskItems['+elockInItemIndex+'].startDate" name="terminalTaskItems['+elockInItemIndex+'].startTime" class="text startTime requireds" value="" onClick="WdatePicker({dateFmt: \'yyyy-MM-dd HH:mm:ss\',startDate:\'%y-%M-%d %H:%m:%s\', maxDate: \'#F{$dp.$D(\\\''+'terminalTaskItems['+elockInItemIndex+'].endDate\\\')}\'});" type="text" btn-fun="clear"/>'
    	}},
    	{ title:'${message("预计到达时间")}', name:'' ,align:'center', width:130, renderer: function(val,item,rowIndex, obj){
			return '<input id="terminalTaskItems['+elockInItemIndex+'].endDate" name="terminalTaskItems['+elockInItemIndex+'].endTime" class="text endTime requireds" value="" onClick="WdatePicker({dateFmt: \'yyyy-MM-dd HH:mm:ss\',startDate:\'%y-%M-%d %H:%m:%s\', minDate: \'#F{$dp.$D(\\\''+'terminalTaskItems['+elockInItemIndex+'].startDate\\\')}\'});" type="text" btn-fun="clear"/>'
    	}},
    	{ title:'${message("配送时长(分钟)")}', name:'' ,align:'center', width:110, renderer: function(val,item,rowIndex, obj){
			
    		var html='<div class="nums-input ov">'+
        	'<input type="button" class="b decrease" value="-"  onMouseDown ="decrease(this,event)"  onMouseUp="editQty(this.nextSibling,event)">'+
        	'<input type="text"  class="t requireds"  name="terminalTaskItems['+elockInItemIndex+'].duration" value="" minData="1" oninput="editQty(this,event)" onpropertychange="editQty(this,event)" >'+
        	'<input type="button" value="+" class="b increase"  onMouseDown ="increase(this,event)" onMouseUp="editQty(this.previousSibling,event)">'+
    	'</div>';
			return html;
		}
		},
		{ title:'${message("容量")}', name:'' ,align:'center', width:110, renderer: function(val,item,rowIndex, obj){
			
			var html='<div class="nums-input ov">'+
        	'<input type="button" class="b decrease" value="-"  onMouseDown ="decrease(this,event)"  onMouseUp="editQty(this.nextSibling,event)">'+
        	'<input type="text"  class="t requireds"  name="terminalTaskItems['+elockInItemIndex+'].volume" value="" minData="1" oninput="editQty(this,event)" onpropertychange="editQty(this,event)" >'+
        	'<input type="button" value="+" class="b increase"  onMouseDown ="increase(this,event)" onMouseUp="editQty(this.previousSibling,event)">'+
    	'</div>';
			return html;
		}
		},
		{ title:'${message("品名")}', name:'' ,align:'center', width:110, renderer: function(val,item,rowIndex, obj){
			var	html = '<input type="text" name="terminalTaskItems['+elockInItemIndex+'].goods" class="text requireds"  btn-fun="clear"/>';
			return html;
		}
		},
		{ title:'${message("数量")}', name:'' ,align:'center', width:110, renderer: function(val,item,rowIndex, obj){
			
			var html='<div class="nums-input ov">'+
        	'<input type="button" class="b decrease" value="-"  onMouseDown ="decrease(this,event)"  onMouseUp="editQty(this.nextSibling,event)">'+
        	'<input type="text"  class="t requireds"  name="terminalTaskItems['+elockInItemIndex+'].quantity" value="" minData="1" oninput="editQty(this,event)" onpropertychange="editQty(this,event)" >'+
        	'<input type="button" value="+" class="b increase"  onMouseDown ="increase(this,event)" onMouseUp="editQty(this.previousSibling,event)">'+
    	'</div>';
			return html;
		}
		},
    	{ title:'${message("备注")}', name:'' ,align:'center', width:110, renderer: function(val,item,rowIndex, obj){
				var	html = '<input type="text" name="terminalTaskItems['+elockInItemIndex+'].memo" class="text memo"  btn-fun="clear"/>';
				return html;
			}
		},
		{ title:'${message("操作")}', align:'center', width:60, renderer:function(val,item){
			elockInItemIndex++;
		return '<a href="javascript:;" class="deleteElock btn-delete">删除</a>';
		}},
	];
	var $tmGrid=$('#table-elock').mmGrid({
		fullWidthRows:true,
		height:'auto',
        cols: cols,
        checkCol: false,
        autoLoad: true,
    });
	
	var ecols = [				
	    		{ title:'${message("终端设备编号")}', name:'terminal_num' ,align:'center',renderer:function(val,item,rowIndex){
	    			var valStr = '<input type="hidden" value="1_'+item.terminal_num+'"/>' + val;
	    			return valStr;
	    		}},
	    		{ title:'${message("事件信息")}', name:'event_message' ,align:'center', width:250},
	    		{ title:'${message("状态信息描述")}', name:'status_desc' ,align:'center', width:110},
	    		{ title:'${message("报警信息")}', name:'warning_message' ,align:'center', width:110},
	    		{ title:'${message("事件发生时间")}', name:'event_time' ,align:'center', width:120},
	    		{ title:'${message("处理人")}', name:'processor' ,align:'center'},
	    		{ title:'${message("车牌号")}', name:'car_number' ,align:'center'},
	    		{ title:'${message("锁编号")}', name:'elock_num' ,align:'center'},
	    		{ title:'${message("舱位")}', name:'position' ,align:'center',renderer:function(val,item,rowIndex){
					var berth=item.berth;
					var position=item.position;
					return (berth==null?'':berth)+','+(position==null?'':position);
				}},
	    		{ title:'${message("经度")}', name:'longitude' ,align:'center', },
	    		{ title:'${message("纬度")}', name:'latitude' ,align:'center', },
	    		{ title:'${message("基站定位数据")}', name:'jzdw' ,align:'center', },
	    		{ title:'${message("电压")}', name:'vol' ,align:'center', width:60},
	    		{ title:'${message("海拔高度")}', name:'altitude' ,align:'center', width:60},
	    		{ title:'${message("速度")}', name:'speed' ,align:'center', width:60},
	    		{ title:'${message("方向")}', name:'direction' ,align:'center', width:60},
	    		{ title:'${message("GPS时间")}', name:'gps_time' ,align:'center', width:120}
	    	];
	    	$emGrid=$('#table-terminal').mmGrid({
	    		fullWidthRows:true,
	            cols: ecols,
	            checkCol: false,
	            height:'auto',
	        });
	
	
	// 删除锁
    $deleteElock.live("click", function() {
        var index = $(this).closest("tr").index();
		$.message_confirm('您确定要删除吗？',function(){
			$tmGrid.removeRow(index);
		})
    });

	// 表单验证
	$inputForm.validate({
		rules: {
			waybillNo: {
				required: true,
			},
			saleOrgId: {
				required:true
			}
		}
	});
	
	$.validator.addClassRules({
		requireds: {
			required: true
		}
	});
	
	//查询机构
	$("#selectSaleOrg").bindQueryBtn({
		type:'fromSaleOrg',
		title:'${message("查询机构")}',
		url:'/saleOrg/select_saleOrg.jhtml'
	});
	 $("form").bindAttribute({
	 	isConfirm:true,
	    callback: function(resultMsg){
	        $.message_timer(resultMsg.type,resultMsg.content,1000,function(){
				location.href= 'edit.jhtml?id='+resultMsg.objx;
			})
	    }
	 });
	 
	//查询机构
		$("#selectToSaleOrg").bindQueryBtn({
			type:'toSaleOrg',
			title:'${message("查询机构")}',
			url:'/saleOrg/select_saleOrg.jhtml'
		});
	
	
	        $("#selectCar").bindQueryBtn({
	            type:'elock',
	            title:'${message("查询")}',
	    		url:'/car/select_elock_car_list.jhtml?multi=2',
	            callback:function(rows){
	                if(rows.length>0){
						var row = rows[0];
						$("input[name='plateNum']").val(row.car_number);
						$("input[name='berth']").val(row.berth);
						$("span.berth").html(row.berth);
	                }
	            }
	        }); 
});	

function addtoSaleOrg(e,flag){
	var $this= $(e);
	var thisnum= 's'+flag;
	var $tr=$this.closest("tr");
	$this.bindQueryBtn({
		type:'toSaleOrg',
		bindClick:false,
		title:'${message("查询组织")}',
		url:'/saleOrg/select_saleOrg.jhtml',
		callback:function(rows){
			if(rows.length>0){
					for (var i = 0; i < rows.length;i++) {
						$tr.find("input.toSaleOrgName").val(rows[i].name);
						$tr.find("input.toSaleOrgId").val(rows[i].id);
					}
				}
		}
	});
}
</script>
</head>
<body>
	<div class="pathh">
		&nbsp;${message("新增任务单")}
	</div>
	<form id="inputForm" action="save.jhtml" method="post" type="ajax" validate-type="validate">
		<input type="hidden" name="memberType" value="ordinary" />
		<div class="tabContent">
			<table class="input input-edit">
			<tr>
				<th>
					<span class="requiredField">*</span>${message("任务单流水号")}:
				</th>
				<td>
				</td>
				<th>
					<span class="requiredField">*</span>${message("任务单编号")}:
				</th>
				<td>
					<span class="error-msg"><input type="text" name="waybillNo" class="text " maxlength="20"   btn-fun="clear"/></span>
				</td>
				<th>
					${message("任务类别")}:
				</th>
				<td>
					<select id="categoryId" name="categoryId" class="text">
						[#list categorys as category]
						<option value="${category.id}">${category.value}</option>
						[/#list]
					</select>
				</td>
				<th>
					<span class="requiredField">*</span>${message("提油机构")}:
				</th>
				<td>
					<span class="search" style="position:relative">
					<input type="hidden" name="fromSaleOrgId" class="text fromSaleOrgId" btn-fun="clear" value="${ saleOrg.id}"/>
					<input type="text" name="fromSaleOrgName" class="text requireds fromSaleOrgName" maxlength="200" onkeyup="clearSelect(this)" value="${saleOrg.name }" readOnly/>
					<input type="button" class="iconSearch" value="" id="selectSaleOrg">
					</span>
				</td>
			</tr>
			<tr>
				<!-- <th>
					${message("开锁模式")}:
				</th>
				<td>
					<select id="unlockMode" name="unlockMode" class="text">
						<option value="0">${message("M1自动模式")}</option>
						<option value="1">${message("M2手动模式")}</option>
					</select>
				</td> -->
				<th>
					${message("状态")}:
				</th>
				<td>
					${message("未完成")}
				</td>
				
				<th>
					${message("备注")}:
				</th>
				<td colspan="5">
					<span class="error-msg"><input type="text" name="memo" class="text " maxlength="20"   btn-fun="clear"/></span>
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">*</span>${message("鹤位")}:
				</th>
				<td>
					<input type="text" name="position" class="text requireds" maxlength="20"   btn-fun="clear"/>
				</td>
				<th>
					<span class="requiredField">*</span>${message("车牌号")}:
				</th>
				<td>
					<span class="search" style="position:relative">
					<input type="text" name="plateNum" class="text plateNum" maxlength="200" onkeyup="clearSelect(this)" value="" readOnly/>
					<input type="button" class="iconSearch" value="" id="selectCar">
					</span>
				</td>
				<th>
					<span class="requiredField">*</span>${message("舱位")}:
				</th>
				<td>
					<span class="berth"></span><input type="hidden" name="berth" class="text " maxlength="20"   btn-fun="clear"/>
				</td>
				<th>
					<span class="requiredField">*</span>${message("卸油机构")}:
				</th>
				<td>
					<span class="search" style="position:relative">
					<input type="hidden" name="toSaleOrgId" class="text toSaleOrgId" btn-fun="clear" value=""/>
					<input type="text" name="toSaleOrgName" class="text requireds toSaleOrgName" maxlength="200" onkeyup="clearSelect(this)" value="" readOnly/>
					<input type="button" class="iconSearch" value="" id="selectToSaleOrg">
					</span>
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">*</span>${message("出发时间")}:
				</th>
				<td>
					<span class="error-msg">
					<input id="startTime" name="startTime" class="text startTime requireds" value="" onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd HH:mm:ss',startDate:'%y-%M-%d %H:%m:%s', maxDate: '#F{$dp.$D(\'endTime\')}'});" type="text" btn-fun="clear"/></span>
				</td>
				<th>
					<span class="requiredField">*</span>${message("预计到达时间")}:
				</th>
				<td>
					<span class="error-msg">
					<input id="endTime" name="endTime" class="text requireds endTime" value="" onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd HH:mm:ss',startDate:'%y-%M-%d %H:%m:%s', minDate: '#F{$dp.$D(\'startTime\')}'});" type="text" btn-fun="clear"/></span>
				</td>
				<th>
					<span class="requiredField">*</span>${message("配送时长(分钟)")}:
				</th>
				<td>
					<div class="nums-input ov">
						<input type="button" class="b decrease" value="-"  onMouseDown ="decrease(this,event)"  >
						<input type="text"  class="t requireds"  name="duration" value="1" minData="1" oninput="editQty(this,event)" onpropertychange="editQty(this,event)" >
						<input type="button" value="+" class="b increase"  onMouseDown ="increase(this,event)" >
					</div>
				</td>
				<th>
					<span class="requiredField">*</span>${message("容量")}:
				</th>
				<td>
					<div class="nums-input ov">
						<input type="button" class="b decrease" value="-"  onMouseDown ="decrease(this,event)"  >
						<input type="text"  class="t requireds"  name="volume" value="1" minData="1" oninput="editQty(this,event)" onpropertychange="editQty(this,event)" >
						<input type="button" value="+" class="b increase"  onMouseDown ="increase(this,event)" >
					</div>
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">*</span>${message("品名")}:
				</th>
				<td>
					<input type="text " name="goods" class="text requireds" maxlength="20"   btn-fun="clear"/>
				</td>
				<th>
					<span class="requiredField">*</span>${message("数量")}:
				</th>
				<td>
					<div class="nums-input ov">
						<input type="button" class="b decrease" value="-"  onMouseDown ="decrease(this,event)"  >
						<input type="text"  class="t requireds"  name="quantity" value="1" minData="1" oninput="editQty(this,event)" onpropertychange="editQty(this,event)" >
						<input type="button" value="+" class="b increase"  onMouseDown ="increase(this,event)" >
					</div>
				</td>
				<th></th><td></td>
				<th></th><td></td>
			</tr>
            	<tr class="partsShow border-L2">
					<th>
						${message("事件信息")}:
					</th>
					<td colspan="7">
					</td>
				</tr>
            	<tr class="border-L2">
            	<td colspan="8">
            		<div>
						<table id="table-terminal"></table>
					</div>
            	</td>
            	</tr>
		</table>
		</div>
		<div class="fixed-top">
			<input type="submit" id="submit_button" class="button sureButton" value="${message("1013")}" />
			<input type="button" onclick="location.reload(true);" class="button resetButton ml15" value="${message("重置")}">
		</div>
	</form>
</body>
</html>